package com.thundern.tdcrawler.selector;

import java.util.ArrayList;
import java.util.List;

public class OrSelector implements Selector {
	
	private List<Selector> selectors = new ArrayList<Selector>();	
	
	public OrSelector(Selector... selectors) {
		for(Selector selector : selectors) {
			this.selectors.add(selector);
		}
	}
	
	public OrSelector(List<Selector> selectors) {
		this.selectors = selectors;
	}
		
	public String select(String text){
		for(Selector selector : selectors) {
			String result = selector.select(text);
			if(result != null) {
				return result;
			}			
		}
		return null;
	}
	
	public List<String> selectList(String text){
		List<String> results = new ArrayList<String>();
		for(Selector selector : selectors) {
			List<String> strings = selector.selectList(text);
			results.addAll(strings);
		}		
		return results;
	}
		
}
